#!/bin/bash
#################nodejs安装##################
#https://nodejs.org/en/download/
#http://download.12306bypass.com/12306Bypass_1.13.18.zip?auth_key=1546390249-5c377c19aee34359975630783eb89fcc-0-9c97c85cc54d84b641769acb1cf3b712

#安装教程
#https://help.aliyun.com/document_detail/50775.html

#定义node安装包文件路径
nodejsPackage=node-v10.15.0-linux-x64
#定义node解压后的文件夹名字
nodejsDir=node-v10.15.0-linux-x64
#定义安装目录
nodejsPath=/usr/lib/

mkdir -p ${nodejsPath}
xz -d ${nodejsPackage}.tar.xz
tar -xvf ${nodejsPackage}.tar
cp -r ${nodejsDir} ${nodejsPath}

rm -f /usr/local/bin/node
rm -f /usr/local/bin/npm
ln -s ${nodejsPath}${nodejsDir}/bin/node /usr/local/bin/node
ln -s ${nodejsPath}${nodejsDir}/bin/npm /usr/local/bin/npm


echo "
#set nodejs environment
NODE_HOME=${nodejsPath}${nodejsDir}
PATH=\$NODE_HOME/bin:\$PATH
export NODE_HOME PATH
" >> /etc/profile
source /etc/profile

echo "nodejs node version:"
node -v
echo "nodejs npm version:"
npm -v

echo "
export NODE_HOME=${nodejsPath}${nodejsDir}";

echo "source /etc/profile
"
echo "finish"
